// pages/exam/examKnow/examKnow.js
var app = getApp();
var config = require('../../../config.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    examId: null,
    examKnow:null,
    // haveCard 1有补考卡 0没有补考卡
    //canPass  1可以跳过录入单位页 2 不可以
    haveCard : -1,
    canPass: -1,
    examNum:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var examId = options.examId
    this.setData({
      examId: examId
    })
    this.initData();
  },

  initData:function(){
    var that = this;
    wx.request({
      url: config.queryExamKonw,
      method: "POST",
      data: {
        examId: that.data.examId,
        openId: app.globalData.openid
      },
      success: function (ret) {
        var data = ret.data
        if (data.success == 0) {
          console.log(data);
          var examInfo = data.rows;
          if (examInfo) {

            var desc = examInfo.exam.introduce 
            that.setData({
              examKnow : desc,
              haveCard: examInfo.haveCard,
              canPass: examInfo.canPass,
              examNum: examInfo.exam_num
            })
          }

        }
      }
    })


  },
 
    /**
   * 去考试
   */
  toExam:function(e){
    var that = this;
    if (that.data.canPass == -1) {
      return;
    }
    if(that.data.haveCard == 0){
        if(that.data.canPass == 1){
          //跳转到答题页面
          wx.redirectTo({
            url: '../examLoading/examLoading?examId=' + that.data.examId
          })
          
        }else{
          //录入页面
          wx.redirectTo({
            url: '../examJoin/examJoin?examId=' + that.data.examId
          })
        }


    }else {
      wx.showToast({
        title: '请使用补考卡考试',
        icon: "none"
      })
    }



  },

  /**
  * 补考证考试
  */
  toOther: function (e) {
    
    var that =  this;
    if (that.data.haveCard != 1){
        wx.showToast({
          title: '您还没有补考卡',
          icon: "none"
        })
        return;
    }
    if (that.data.haveCard == 1){
        //使用补考卡 
      wx.redirectTo({
        url: '../examGoing/examGoing?examId=' + that.data.examId
      })

    }
  },

})